//
//  Opinion_GetComm_Task.m
//  ipad.mobileoa.szjj
//
//  Created by wangzhigang on 13-12-11.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "Opinion_GetComm_Task.h"
#import "OpinionInfo.h"
#import "GDataXMLNode.h"

@implementation Opinion_GetComm_Task

-(void)execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    NSString *userguid = [userDefaults objectForKey:Epoint_User_UserGuid];
    NSString *type = [params objectForKey:@"type"];
   
    
    NSString *doMethod = @"Opinion_GetComm";
    if ([@"personal" isEqualToString:type]) {
        doMethod=@"Opinion_GetUserOpinion";
    }
    
    
    NSString *ParasXml = @"<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid></paras>";
    EpointWebServiceUtil *webserviceHelper = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:doMethod];
    ParasXml = [NSString stringWithFormat:ParasXml,userguid];
    ParasXml = [EpointStringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    if ([self validateXMLWS:bs]) {
        [self exeSuccessWithData:[self getListArray:bs]];
    }
}

-(NSMutableArray *)getListArray:(NSString *)_xml
{
    NSString *xmldata = [EpointStringUtil getXMLFormatedAttributeBsWithTag:_xml xmlTag:@"OpinionList"];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xmldata  options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"OpinionInfo"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        OpinionInfo *m = [[OpinionInfo alloc]init];
        GDataXMLElement *OpinionText = [[arr elementsForName:@"OpinionText"] objectAtIndex:0];
        m.OpinionText = [OpinionText stringValue];
               
        [listmp addObject:m];
    }
    
    return listmp;
}



@end
